<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/view/include/taglib.jsp"%>
<html lang="cn" class="app">
<head>
    <meta charset="utf-8" />
    <title>${dict:getConfigValueByKey('WEB_NAME','管理平台')} | 单位管理</title>
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="icon" type="image/png" href="icon.png">
    <link rel="apple-touch-icon-precomposed" href="icon.png">
    <link rel="stylesheet" href="${ctxStatic}/css/bootstrap.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/css/app.css" type="text/css" />
    <link rel="stylesheet" href="${ctxStatic}/js/ztree/css/zTreeStyle.css">
    <link rel="stylesheet" href="${ctxStatic}/js/chosen/chosen.css" type="text/css" />
    <%--<link rel="stylesheet" href="${ctxStatic}/js/page/paging.css" type="text/css" />--%>
    <!--[if lt IE 9]>
    <script src="${ctxStatic}/js/ie/html5shiv.js"></script>
    <script src="${ctxStatic}/js/ie/respond.min.js"></script>
    <script src="${ctxStatic}/js/ie/excanvas.js"></script>
    <![endif]-->
</head>
<body>
<section class="scrollable wrapper">
    <div class="row">
        <div class="col-lg-12">
            <!-- 引导开始 -->
            <ul class="breadcrumb">
                <li><a href="${ctx}/welcome"><i class="fa fa-home"></i> 主页</a></li>
                <li>系统设置</li>
                <li class="active">单位管理</li>
                <li class="active">单位编辑</li>
            </ul>
            <!-- 引导结束 -->
        </div>
    </div>

    <%--基本信息--%>
    <section class="panel panel-default">
        <header class="panel-heading font-bold">单位编辑</header>

        <div class="panel-body">
            <div class="col-lg-2 col-md-2 col-sm-2">
                <div class="text-center m-b m-t">
                    <a href="#" class="thumb-lg">
                        <c:if test="${organization.photo !=null && organization.photo != '' }">
                            <img id="userHeadImage" src="${dict:getConfigValueByKey('UPLOAD_READ_PATH_IMG','')}${organization.photo}?${currentTime}" class="img-circle" style="height:auto;width:128px;">
                        </c:if>
                        <c:if test="${organization.photo ==null || organization.photo == '' }">
                            <img id="userHeadImage" src="${ctxStatic}/images/a0.png" class="img-circle" style="height:auto;width:128px;">
                        </c:if>
                    </a>
                    <div>
                        <style type="text/css">
                            .div2{width:100px;height:40px}
                            .imageIframe{width:0;height:0;}
                        </style>
                        <script>
                            function loadHeadImg(url){
                                $("#userHeadImage").attr("src","${dict:getConfigValueByKey('UPLOAD_READ_PATH_IMG','')}"+url +"?" + new Date());
                                showMsg("照片上传成功！");
                                $("#fileInput").val("");
                            }
                        </script>
                        <form method="post" enctype="multipart/form-data" target="head_userpic" action="${ctx}/organization/uploadHeadImg">
                            <%--<div class="h3 m-t-xs m-b-xs">${user.name}</div>--%>
                            <div class="h3 m-t-xs m-b-xs" style="text-align: center;">
                                <input id="fileInput" type="file" name="file" style="font-size: 14px;float:left;width:100%;height:30px;" required/>
                                <input type="hidden" name="orgId" value="${organization.id}"  required/>

                                <button type="submit" class="btn btn-sm btn-info" style="">上传</button>
                            </div>
                        </form>
                        <div class="div2">
                            <iframe class="imageIframe" frameborder=0 name="head_userpic"></iframe>
                        </div>
                        <%--<small class="text-muted">--%>
                        <%--</small>--%>
                    </div>
                </div>
            </div>
            <form id="orgForm" class="bs-example form-horizontal" method="post">
                <input type="hidden" name="id" value="${organization.id}" />
                <input type="hidden" id="parentId" name="parentId" value="${organization.parentId}" />
                <div class="col-lg-10 col-md-10 col-sm-10">
                    <div class="form-group">
                        <label class="col-lg-2 col-md-2 col-sm-2 control-label">上级单位：</label>
                        <div class="col-lg-4 col-md-4 col-sm-4 ">
                            <input type="text" class="form-control" id="parentName" minlength="1" value="${organization.organization.name}" readonly>(为了安全，不允许修改单位层级)
                        </div>
                        <%--<div class="col-lg-4 col-md-4 col-sm-4 ">--%>
                            <%--<button id="menuBtn" type="button" class="btn btn-s-md btn-default">选择</button>--%>
                        <%--</div>--%>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-2 col-md-2 col-sm-2 control-label"><span class="text-danger">*</span>单位名称：</label>
                        <div class="col-lg-4 col-md-4 col-sm-4">
                            <input type="text" id="name" name="name" class="form-control" placeholder="单位名称（必填）" value="${organization.name}" required>
                        </div>
                        <label class="col-lg-2 col-md-2 col-sm-2 control-label"><span class="text-danger">*</span>简称：</label>
                        <div class="col-lg-4 col-md-4 col-sm-4">
                            <input type="text" id="shortName" class="form-control" name="shortName" placeholder="简称" value="${organization.shortName}" required />
                        </div>
                    </div>

                    <div class="form-group">


                        <label class="col-lg-2 col-md-2 col-sm-2 control-label">是否可用：</label>
                        <div class="col-lg-4 col-md-4 col-sm-4">
                            <select name="available" class="form-control" >
                                <c:forEach items="${yn}" var="m">
                                    <option value="${m.value}" <c:if test="${organization.available==m.value}">selected="selected"</c:if>>${m.label}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-2 col-lg-10 col-md-10 col-sm-10">
                            <shiro:hasPermission name="sys:organization:edit">
                                <button type="button" class="btn btn-s-md btn-info" onclick="updateOrg()">保存</button>
                            </shiro:hasPermission>
                            <button type="button" class="btn btn-s-md btn-danger" onclick="closeSelfModel()">关闭</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </section>

</section>
<div id="menuContent" class="menuContent" style="display:none;position: absolute;z-index: 10000;background-color: #eee;border: 1px solid #ccc;">
    <style>.line{height:auto;}</style><%--这个不能删除--%>
    <ul id="tree" class="ztree" style="margin-top:0;"></ul>
</div>
</body>
<script src="${ctxStatic}/js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="${ctxStatic}/js/bootstrap.js"></script>
<!-- App -->
<script type="text/javascript" src="${ctxStatic}/js/tools.js?version=${ctxVersion}"></script>
<script type="text/javascript" src="${ctxStatic}/js/page/paging.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/tmpl/jquery.tmpl.js"></script>
<script src="${ctxStatic}/js/ztree/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/js/chosen/chosen.jquery.min.js"></script>
<%--<script src="${ctxStatic}/js/ztree/js/jquery.ztree.excheck-3.5.min.js"></script> 复选框使用--%>
<script>
    <%--$(function(){--%>
        <%--var setting = {--%>
            <%--data: {--%>
                <%--simpleData: {--%>
                    <%--enable: true--%>
                <%--}--%>
            <%--},--%>
            <%--callback : {--%>
                <%--onClick : function(event, treeId, treeNode) {--%>
                    <%--//点击回调方法--%>
                    <%--ztreeOnClickCall && ztreeOnClickCall(treeNode);--%>
                    <%--$("#parentName").val(treeNode.name);--%>
                    <%--hideMenu();--%>
                <%--}--%>
            <%--}--%>
        <%--};--%>
        <%--var zNodes =[--%>
            <%--<c:forEach items="${organizationList}" var="o" varStatus="status">--%>
            <%--{ id:"${o.id}", pId:"${o.parentId}",no:'${o.no}', name:"${o.name}", open:true}<c:if test="${!status.last}">,</c:if>--%>
            <%--</c:forEach>--%>
        <%--];--%>
        <%--$(document).ready(function(){--%>
            <%--var ztree = $.fn.zTree.init($("#tree"), setting, zNodes);--%>
            <%--ztree.expandAll(true);--%>
        <%--});--%>

        <%--$("#menuBtn").click(showMenu);--%>
    <%--})--%>

    <%--//ztree点击回调--%>
    <%--function ztreeOnClickCall(treeNode){--%>
        <%--$("#parentId").val(treeNode.id);--%>
    <%--}--%>
    <%--//展示树选择区域--%>
    <%--function showMenu() {--%>
        <%--var cityObj = $("#parentName");--%>
        <%--var cityOffset = $("#parentName").offset();--%>
        <%--$("#menuContent").css({--%>
            <%--left: cityOffset.left + "px",--%>
            <%--top: cityOffset.top + cityObj.outerHeight() + "px"--%>
        <%--}).slideDown("fast");--%>

        <%--$("body").bind("mousedown", onBodyDown);--%>
    <%--}--%>
    <%--//隐藏树选择区域--%>
    <%--function hideMenu() {--%>
        <%--$("#menuContent").fadeOut("fast");--%>
        <%--$("body").unbind("mousedown", onBodyDown);--%>
    <%--}--%>
    <%--//点击其他区域事件-用于隐藏选择树--%>
    <%--function onBodyDown(event) {--%>
        <%--if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) {--%>
            <%--hideMenu();--%>
        <%--}--%>
    <%--}--%>

    /**更新单位 @author gaoy*/
    function updateOrg(){
        if(isBlankCheck("name,shortName","单位名称,简称")){
            var loadingLayer = layer.load(1, {shade: [0.1,'#fff']});//loading
            //根据项目标识获取目录
            $.ajax({
                type: 'post',
                url: '${ctx}/organization/updateOrg.json?timeStamp='+new Date().getTime(),
                dataType:"json",
                data: $("#orgForm").serialize(),
                success: function (data) {
                    layer.close(loadingLayer);
                    showMsg(data.desc);
                },error:function(){
                    layer.close(loadingLayer);
                    showMsg("点击过快或程序异常");
                }
            });
        }
    }
    /** 关闭当前弹出框并执行 */
    function closeSelfModel(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.searchPage(1);
        parent.loadTree();
        parent.layer.close(index);
    }
</script>
</html>
